Ext.onReady(function(){
	
	//搜索框
	var searchBar = new Ext.form.Panel({
		id:'searchUserForm',
		border:false,
		//style: 'border-width:0',
		items:[
			{
			xtype:'toolbar',
			//border:'0',
			style: 'border-width:0',
			items:[
			'真实姓名:',
			{
				xtype:'textfield', 
			 	name:'userCname', 
			 	width:120
			},
			'账户:',
			{
				xtype:'textfield', 
			 	name:'username', 
				width:120
			},
			{
				xtype:'button', 
			 	text:'查询', 
			 	iconCls:'com-query',
			 	handler:function(){
			 		//TODO
			 		//Ext.getCmp('userGrid').refresh();
			 	}
			}]
			}
		]
	});
	
	var cmdBar = new Ext.toolbar.Toolbar({
		style: 'border-width:0',
		items: [
		{
			text: '新增',
			scale: 'medium',
			itemId: 'addBtn',
			iconCls: 'com-add',
			handler: function(){
				EditUser.openEditWin();
			} //,scope: this
		},'-',
		{
			xtype:'button',
			text: '修改',
			scale: 'medium',
			itemId: 'updateBtn',
			iconCls: 'com-update',
			handler: function(){
				var sel = userGrid.getSelectionModel().getSelection();
				var ids = new Array();
				if(sel.length > 0){
					for(var i=0; i<sel.length; i++){
						ids.push(sel[i].get('id'));
					}
				}
				EditUser.openEditWin(ids[0]);
			}
		}]
	});
	
	var userTopBar = new Ext.panel.Panel({
		width:'100%',
		bodyStyle: 'border-width:0',
		items: [searchBar,cmdBar ]
	});
	
	var userStone = new Ext.data.Store({
		model: 'UserVO',
		pageSize: 10,
		remoteSort: true,
	    proxy: {
	        type: 'ajax',
	        url: Common.ctx+'/user/search',
			reader: {
				type: 'json',
				root: 'data.list',
				totalProperty: 'data.totalCount'
			}
	    }
	});
	
	var pagingToolBar = {
	    xtype:'pagingtoolbar',
		pageSize: 10,
		store: userStone,
		dock: 'bottom',
		displayInfo: true,
		displayMsg: "显示第 {0} 条到 {1} 条记录，一共 {2} 条",
		emptyMsg: "没有记录"
	};
	
	userStone.load({params:{start:0, limit:this.pageSize}});
	console.log( userStone.getTotalCount() );
	
	//用户Grid
	var userGrid = new Ext.grid.Panel({
		border:false,
		store: userStone,
		columns: [ 
            {text: "用户名", width: 200, dataIndex: 'username', sortable: false}, 
            {text: "真名", width: 100, dataIndex: 'userCname', sortable: false},
            {text: "性别", width: 100, dataIndex: 'sex', sortable: false},
            {text: "电话", width: 120, dataIndex: 'phone', sortable: false}, 
            {text: "E-mail", width: 100, dataIndex: 'email', sortable: false},
            {text: "是否激活", width: 120, dataIndex: 'valid', sortable: false}
        ], 
		selModel: Ext.create('Ext.selection.CheckboxModel'),
		tbar:[userTopBar],
		dockedItems:[pagingToolBar]
	});
	
	Ext.create('Ext.container.Viewport', {
		border: false,
		layout : 'fit',
		items: userGrid
	});
	
});